<script src="<?php echo base_url().'assets/js/jquery.tablesorter.min.js'; ?>" type="text/javascript"></script>
<script type = "text/javascript">
	$(document).ready(function(){
		$('#delete').click(function(){
			var n
			n = $("input[name='checkid[]']:checked").length
			if( n <= 0 ) {
				alert('Please select users from the list to delete.')
				return false
			} else {
				if ( confirm('Are you sure you want to delete records?') == true ){
					//$('#task').val('delete')
					$('#frmAds').submit()
				} else {
					return false
				}
			}
			return false
		})

		$('#checkall').click(function(){
			var n
			n = $("input[name='checkid[]']").length
			for( var i=0; i<n; i++){
				if( $("#checkall").is(":checked") ){
					$("input[name='checkid[]']").attr('checked', true);
				} else {
					$("input[name='checkid[]']").attr('checked', false);
				}
			}
			$("#checkboxall").removeClass("checkall").addClass("uncheckall");
		});

		$("#adminAdsTable").tablesorter({
			 headers: {
               0: {sorter: false},
               1: {sorter: false},
               2: {sorter: false},
               //7: {sorter: false}

             }
		});

	});
	function toggle(task, postid){
		var url = '<?php echo base_url('admin/advertisements/toggle'); ?>'
		$.ajax({
			url: url,
			type:'post',
			data: 'task='+task+'&postid='+postid,
			success:function(data){
		//alert(data);return false;
				$("#toggle_"+postid).html(data)
			}
		})
	}

</script>
<div class="content">
	<form method="POST" id="frmAds" action="<?php echo base_url()?>admin/advertisements/index">
	<div id="top-heading">
		<div id="h-links">
			<?php
			echo anchor(site_url(). 'admin/advertisements/create', 'Add New', 'id="add-new" class="button"');
			echo anchor('#', 'Delete', 'id="delete" class="button"');

			?>

		</div>
		<div id="pagination">
			<?php echo $pagination; ?>
		</div>
	</div>

	<div id = "wrap-table">
			<?php $this->message->display();?>
			<table id = "adminAdsTable" class = "admin-table">
				<thead>
					<tr>
						<th width='3%'>#</th>
						<th width='3%'><input type="checkbox" id="checkall" class="inputbox"/></th>
						<th width='10%'>Banner</th>
						<th>Name</th>
						<th width='15%'>Section</th>
						<th width='15%'>Date</th>
						<th width='8%'>Publish</th>
						<th width='5%'>ID</th>
						<th width='8%'>Action</th>
					</tr>
				</thead>
				<tbody>
				<?php foreach ($testi_qry_limited as $k=>$row): ?>
					<tr>
						<td><?php echo $k+1; ?></td>
						<td><input type="checkbox" name="checkid[]" value="<?php echo $row->advertisementsid; ?>" class="checkbox" /></td>
						<td><img src = "<?php echo base_url().'assets/images'.$row->banner; ?>" width = "50%" height = "50%" /></td>
						<td><?php echo $row->name; ?></td>
						<td><?php echo $row->section; ?></td>
						<td><?php echo $row->date_added; ?></td>
						<td>
							<?php $this->load->helper('Boolean_helper');
							echo Boolean_helper::status($row->status, true, $row->advertisementsid);
							?>
						</td>
						<td><?php echo $row->advertisementsid; ?></td>
						<td><a href = "<?php echo base_url();?>admin/advertisements/edit/<?php echo $row->advertisementsid;?>">edit</a></td>
					</tr>
					<?php endforeach; ?>
				</tbody>
			</table>

	</div><!--end of wrap-table-->
	<input type="hidden" name="task" value="delete" id="task" />
	</form>
</div><!--end of content-->
